package com.blog.sys.service;

import com.blog.sys.controller.SysUserController;
import com.blog.sys.dao.SysRoleRepository;
import com.blog.sys.entity.SysRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.PrintWriter;
import java.io.StringWriter;

@Service
public class RoleService {
    private final static Logger logger = LoggerFactory.getLogger(SysUserController.class);

    @Autowired
    private SysRoleRepository sysRoleRepository;

    public SysRole findByRoleName(String roleName){
        SysRole role = null;
        try {
            role = sysRoleRepository.findByRole(roleName);
        } catch (RuntimeException e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            logger.error(sw.toString());
        }
        return role;
    }

}
